<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_actions_block_EditFolderAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$docId = $this->getRequestParameter("docId");
		$docLang = $this->getRequestParameter("docLang");

        $errors = array();

		if(isset($docId) && isset($docLang))
		{
			$folder = $this->getDocumentProvider()->getByUniqueId($docId, $docLang);
		}
		
		$formValues = $this->getFormValues("form");
		
		if(count($formValues) > 0)
		{
			if($formValues["label"] == "")
			{
				$errors["label"] = $this->getLocale('backoffice.errors.required');
				$errors["status"] = "failed";
			}
			else
			{
				$folder->setLabel($formValues["label"])->save(false);
			}
		}
		
		$this->addToModel("errors", $errors);
		$this->addToModel("folder", $folder);
		$this->setView('success');
	}	
}